#include <stdio.h>
#include <string.h>
struct Data
{
    int num;
    int fir;
    int sec;
    int thi;
    int ave;
};
int main ()
{
    int n,j;
    char a[100][100];
    struct Data student;
    printf("Please input the number of students you should input:\n");
    scanf("%d",&n);

    for (int i=0;i<n;i++)
    {
        printf("Please input the %d  student information: student number, the first grade ,the second ,the third.\n",i+1);
        scanf("%d%d%d%d",&student.num,&student.fir,&student.sec,&student.thi);
        student.ave=(student.fir+student.sec+student.thi)/3;
       
       sprintf(a[i],"%d %d %d %d %d",student.num,student.fir,student.sec,student.thi,student.ave);
       printf("%s\n",a[i]);
    }
    FILE *fp=fopen("C:\\Users\\lenovo\\Desktop\\stud.csv","w");
    if(fp== NULL)
    {
        printf("文件打开失败\n");
    }
    for(int j=0;j<n;j++)
    {
        fputs(a[j],fp);
        fputs("\n",fp);
    }
        fclose(fp);

    return 0;
}